import React, { useEffect, useState } from 'react'
import { Modal } from 'antd'
import {SchemaForm, Item, FormItemGrid,Layout, Submit,Reset} from '@amazebird/antd-schema-form'
import {forEach} from 'lodash-es'

const labelCol = {
  span: 5 
}

const wrapperCol = {
  span: 16
}
export default function SmartForm(props){
  const {schema,children,onSubmit,sumbitText, onReset,resetText, columnNum, ...rest} = props
  //todo 验证scheema，只能用于一层的schema，不能够
  const [fields, setFields] = useState<string[]>([])
  useEffect(()=>{
    const newFields:string[] = []
    forEach(schema,(value,key)=>{newFields.push(key)})
    setFields(newFields)
  },[])


  return (
    <SchemaForm schema={schema} {...rest} >
      <FormItemGrid colCount={3}>
        {
          fields.map((field)=>{
            return <Item key={field} labelCol={labelCol} wrapperCol={wrapperCol} field={field} />
          })
        }
      </FormItemGrid>
      <Layout offset={8}>
        <Submit></Submit>
        <Reset></Reset>
      </Layout>
    </SchemaForm>
  )
}